<template>
  <div class="app-container">
    <el-card v-show="showSearch" class="mb10" shadow="hover">
      <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="120px" size="small">
        <el-form-item label="卡号" prop="params.cardNo">
          <el-input
            v-model="queryParams.params.cardNo"
            clearable
            placeholder="请输入卡号"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="油站ID" prop="params.stationId">
          <el-input
            v-model="queryParams.params.stationId"
            clearable
            placeholder="请输入油站ID"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="会员ID" prop="params.memberId">
          <el-input
            v-model="queryParams.params.memberId"
            clearable
            placeholder="请输入会员ID"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="可用油品" prop="params.usableFuel">
          <el-input
            v-model="queryParams.params.usableFuel"
            clearable
            placeholder="请输入可用油品"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="可用油站" prop="params.usableStation">
          <el-input
            v-model="queryParams.params.usableStation"
            clearable
            placeholder="请输入可用油站"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="建卡日期" prop="params.buildDate">
          <el-date-picker v-model="queryParams.params.buildDate"
                          clearable
                          placeholder="请选择建卡日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公司ID" prop="params.companyId">
          <el-input
            v-model="queryParams.params.companyId"
            clearable
            placeholder="请输入公司ID"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="是否特殊优惠" prop="params.specialDiscount">
          <el-input
            v-model="queryParams.params.specialDiscount"
            clearable
            placeholder="请输入是否特殊优惠"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="充值活动uid" prop="params.rechargeActUid">
          <el-input
            v-model="queryParams.params.rechargeActUid"
            clearable
            placeholder="请输入充值活动uid"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item class="ml10">
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card shadow="hover">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['card:master:add']"
            icon="el-icon-plus"
            plain
            size="mini"
            type="primary"
            @click="handleAdd"
          >新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['card:master:edit']"
            :disabled="single"
            icon="el-icon-edit"
            plain
            size="mini"
            type="success"
            @click="handleUpdate"
          >修改
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['card:master:remove']"
            :disabled="multiple"
            icon="el-icon-delete"
            plain
            size="mini"
            type="danger"
            @click="handleDelete"
          >删除
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['card:master:export']"
            icon="el-icon-download"
            plain
            size="mini"
            type="warning"
            @click="handleExport"
          >导出
          </el-button>
        </el-col>
        <right-toolbar :columns="columns" :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="masterList" border @sort-change="handleSortChange"
                @selection-change="handleSelectionChange">
        <el-table-column align="center" type="selection" width="55"/>
        <el-table-column v-if="columns[0].visible" align="center" label="主键" prop="id" show-overflow-tooltip/>
        <el-table-column v-if="columns[1].visible" align="center" label="卡号" prop="cardNo" show-overflow-tooltip/>
        <el-table-column v-if="columns[2].visible" align="center" label="油站ID" prop="stationId"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[3].visible" align="center" label="会员ID" prop="memberId" show-overflow-tooltip/>
        <el-table-column v-if="columns[4].visible" align="center" label="卡名称" prop="cardName" show-overflow-tooltip/>
        <el-table-column v-if="columns[5].visible" align="center" label="卡类型" prop="cardType" show-overflow-tooltip/>
        <el-table-column v-if="columns[6].visible" align="center" label="卡状态" prop="cardStatus"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[7].visible" align="center" label="账户余额" prop="balance"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[8].visible" align="center" label="本金余额" prop="capitalBalance"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[9].visible" align="center" label="赠金余额" prop="giftBalance"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[10].visible" align="center" label="开票类型" prop="invoiceType"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[11].visible" align="center" label="可用油品" prop="usableFuel"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[12].visible" align="center" label="可用油站" prop="usableStation"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[13].visible" align="center" label="比高油品" prop="comparableFuel"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[14].visible" align="center" label="积分数量" prop="points"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[15].visible" align="center" label="优惠类型" prop="discountType"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[16].visible" align="center" label="建卡日期" prop="buildDate"
                         show-overflow-tooltip>
          <template #default="scope">
            <span>{{ formatDateTime(scope.row.buildDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[17].visible" align="center" label="用户名称" prop="username"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[18].visible" align="center" label="用户电话" prop="phone" show-overflow-tooltip/>
        <el-table-column v-if="columns[19].visible" align="center" label="身份证号码" prop="idCardNo"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[20].visible" align="center" label="车牌号码" prop="carNumber"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[21].visible" align="center" label="公司名称" prop="companyId"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[22].visible" align="center" label="联系地址" prop="address"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[23].visible" align="center" label="是否特殊优惠" prop="specialDiscount"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[24].visible" align="center" label="0优惠" prop="discount0"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[25].visible" align="center" label="-10优惠" prop="discount10"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[26].visible" align="center" label="92优惠" prop="discount92"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[27].visible" align="center" label="95优惠" prop="discount95"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[28].visible" align="center" label="98优惠" prop="discount98"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[29].visible" align="center" label="余额报警值" prop="balanceWarningValue"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[30].visible" align="center" label="充值活动uid" prop="rechargeActUid"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[31].visible" align="center" label="副卡数量" prop="cardSecondCount"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[32].visible" align="center" label="创建人名称" prop="creatorName"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[33].visible" align="center" label="创建时间" prop="createDate"
                         show-overflow-tooltip>
          <template #default="scope">
            <span>{{ formatDateTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[34].visible" align="center" label="编辑人名称" prop="modifierName"
                         show-overflow-tooltip/>
        <el-table-column v-if="columns[35].visible" align="center" label="编辑时间" prop="modifiedDate"
                         show-overflow-tooltip>
          <template #default="scope">
            <span>{{ formatDateTime(scope.row.modifiedDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[36].visible" align="center" label="备注信息" prop="remark"
                         show-overflow-tooltip/>
        <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button
                v-hasPermi="['card:master:edit']"
                icon="el-icon-edit-outline"
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"/>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button
                v-hasPermi="['card:master:remove']"
                icon="el-icon-delete"
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"/>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改主卡信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="1100px">
      <el-form ref="form" :model="form" :rules="rules">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="卡号" prop="cardNo">
              <el-input v-model="form.cardNo" placeholder="请输入卡号"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="油站名称" prop="stationId">
              <el-input v-model="form.stationId" placeholder="请输入油站ID"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会员名称" prop="memberId">
              <el-input v-model="form.memberId" placeholder="请输入会员ID"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="卡名称" prop="cardName">
              <el-input v-model="form.cardName" placeholder="请输入卡名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="账户余额" prop="balance">
              <el-input v-model="form.balance" placeholder="请输入账户余额"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="本金余额" prop="capitalBalance">
              <el-input v-model="form.capitalBalance" placeholder="请输入本金余额"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="赠金余额" prop="giftBalance">
              <el-input v-model="form.giftBalance" placeholder="请输入赠金余额"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="积分数量" prop="points">
              <el-input v-model="form.points" placeholder="请输入积分数量"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="可用油站" prop="usableStation">
              <el-input v-model="form.usableStation" placeholder="请输入可用油站"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="比高油品" prop="comparableFuel">
              <el-input v-model="form.comparableFuel" placeholder="请输入比高油品"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="可用油品" prop="usableFuel">
              <el-input v-model="form.usableFuel" placeholder="请输入可用油品"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="建卡日期" prop="buildDate">
              <el-date-picker v-model="form.buildDate"
                              clearable
                              placeholder="请选择建卡日期"
                              style="width: 100%"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="用户名称" prop="username">
              <el-input v-model="form.username" placeholder="请输入用户名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入用户电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="身份证号码" prop="idCardNo">
              <el-input v-model="form.idCardNo" placeholder="请输入身份证号码"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车牌号码" prop="carNumber">
              <el-input v-model="form.carNumber" placeholder="请输入车牌号码"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="公司名称" prop="companyId">
              <el-input v-model="form.companyId" placeholder="请输入公司名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入联系地址"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否特殊优惠" prop="specialDiscount">
              <el-input v-model="form.specialDiscount" placeholder="请输入是否特殊优惠"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="0#优惠" prop="discount0">
              <el-input v-model="form.discount0" placeholder="请输入0#优惠"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="-10#优惠" prop="discount10">
              <el-input v-model="form.discount10" placeholder="请输入-10#优惠"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="92#优惠" prop="discount92">
              <el-input v-model="form.discount92" placeholder="请输入92#优惠"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="95优惠" prop="discount95">
              <el-input v-model="form.discount95" placeholder="请输入95优惠"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="98#优惠" prop="discount98">
              <el-input v-model="form.discount98" placeholder="请输入98#优惠"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="余额报警值" prop="balanceWarningValue">
              <el-input v-model="form.balanceWarningValue" placeholder="请输入余额报警值"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="充值活动uid" prop="rechargeActUid">
              <el-input v-model="form.rechargeActUid" placeholder="请输入充值活动uid"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="副卡数量" prop="cardSecondCount">
              <el-input v-model="form.cardSecondCount" placeholder="请输入副卡数量"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注信息" prop="remark">
              <el-input v-model="form.remark" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入备注信息"
                        type="textarea"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addMaster, getMaster, listMaster, updateMaster} from "@/api/card/master";
import {formatDateTime, nowCnFormatDateTime} from "@/utils/date";

export default {
  name: "Master",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主卡信息表格数据
      masterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sortName: 'id',
        sortOrder: 'desc',
        params: {
          cardNo: undefined,
          stationId: undefined,
          memberId: undefined,
          cardName: undefined,
          cardType: undefined,
          cardStatus: undefined,
          balance: undefined,
          capitalBalance: undefined,
          giftBalance: undefined,
          invoiceType: undefined,
          usableFuel: undefined,
          usableStation: undefined,
          comparableFuel: undefined,
          points: undefined,
          discountType: undefined,
          buildDate: undefined,
          username: undefined,
          phone: undefined,
          idCardNo: undefined,
          carNumber: undefined,
          companyId: undefined,
          address: undefined,
          password: undefined,
          specialDiscount: undefined,
          discount0: undefined,
          discount10: undefined,
          discount92: undefined,
          discount95: undefined,
          discount98: undefined,
          balanceWarningValue: undefined,
          rechargeActUid: undefined,
          cardSecondCount: undefined,
          creatorId: undefined,
          creatorName: undefined,
          createDate: undefined,
          modifierId: undefined,
          modifierName: undefined,
          modifiedDate: undefined,
          active: undefined,
        }
      },
      columns: [
        {key: 0, label: `主键`, visible: false},
        {key: 1, label: `卡号`, visible: true},
        {key: 2, label: `油站`, visible: true},
        {key: 3, label: `会员`, visible: true},
        {key: 4, label: `卡名称`, visible: false},
        {key: 5, label: `卡类型`, visible: true},
        {key: 6, label: `卡状态`, visible: true},
        {key: 7, label: `账户余额`, visible: false},
        {key: 8, label: `本金余额`, visible: true},
        {key: 9, label: `赠金余额`, visible: true},
        {key: 10, label: `开票类型`, visible: false},
        {key: 11, label: `可用油品`, visible: true},
        {key: 12, label: `可用油站`, visible: true},
        {key: 13, label: `比高油品`, visible: false},
        {key: 14, label: `积分数量`, visible: false},
        {key: 15, label: `优惠类型`, visible: false},
        {key: 16, label: `建卡日期`, visible: false},
        {key: 17, label: `用户名称`, visible: false},
        {key: 18, label: `用户电话`, visible: false},
        {key: 19, label: `身份证号码`, visible: false},
        {key: 20, label: `车牌号码`, visible: false},
        {key: 21, label: `公司名称`, visible: true},
        {key: 22, label: `联系地址`, visible: false},
        {key: 23, label: `是否特殊优惠`, visible: false},
        {key: 24, label: `0#优惠`, visible: false},
        {key: 25, label: `-10#优惠`, visible: false},
        {key: 26, label: `92#优惠`, visible: false},
        {key: 27, label: `95优惠`, visible: false},
        {key: 28, label: `98优惠`, visible: false},
        {key: 29, label: `余额报警值`, visible: true},
        {key: 30, label: `充值活动uid`, visible: true},
        {key: 31, label: `副卡数量`, visible: false},
        {key: 32, label: `创建人名称`, visible: false},
        {key: 33, label: `创建时间`, visible: false},
        {key: 34, label: `编辑人名称`, visible: false},
        {key: 35, label: `编辑时间`, visible: false},
        {key: 36, label: `备注信息`, visible: true},
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cardNo: [
          {
            required: true, message: "卡号不能为空", trigger: "blur"
          }
        ],
        stationId: [
          {
            required: true, message: "油站ID不能为空", trigger: "blur"
          }
        ],
        memberId: [
          {
            required: true, message: "会员ID不能为空", trigger: "blur"
          }
        ],
        cardName: [
          {
            required: true, message: "卡名称不能为空", trigger: "blur"
          }
        ],
        cardType: [
          {
            required: true, message: "卡类型不能为空", trigger: "change"
          }
        ],
        cardStatus: [
          {
            required: true, message: "卡状态：正常、挂失不能为空", trigger: "change"
          }
        ],
        balance: [
          {
            required: true, message: "账户余额不能为空", trigger: "blur"
          }
        ],
        capitalBalance: [
          {
            required: true, message: "本金余额不能为空", trigger: "blur"
          }
        ],
        giftBalance: [
          {
            required: true, message: "赠金余额不能为空", trigger: "blur"
          }
        ],
        invoiceType: [
          {
            required: true, message: "不能为空", trigger: "change"
          }
        ],
        usableFuel: [
          {
            required: true, message: "可用油品不能为空", trigger: "blur"
          }
        ],
        usableStation: [
          {
            required: true, message: "可用油站不能为空", trigger: "blur"
          }
        ],
        comparableFuel: [
          {
            required: true, message: "比高油品不能为空", trigger: "blur"
          }
        ],
        points: [
          {
            required: true, message: "积分数量不能为空", trigger: "blur"
          }
        ],
        discountType: [
          {
            required: true, message: "优惠类型：1不能为空", trigger: "change"
          }
        ],
        buildDate: [
          {
            required: true, message: "建卡日期不能为空", trigger: "blur"
          }
        ],
        username: [
          {
            required: true, message: "用户名称不能为空", trigger: "blur"
          }
        ],
        phone: [
          {
            required: true, message: "用户电话不能为空", trigger: "blur"
          }
        ],
        idCardNo: [
          {
            required: true, message: "身份证号码不能为空", trigger: "blur"
          }
        ],
        carNumber: [
          {
            required: true, message: "车牌号码不能为空", trigger: "blur"
          }
        ],
        companyId: [
          {
            required: true, message: "公司ID不能为空", trigger: "blur"
          }
        ],
        address: [
          {
            required: true, message: "联系地址不能为空", trigger: "blur"
          }
        ],
        password: [
          {
            required: true, message: "支付密码不能为空", trigger: "blur"
          }
        ],
        specialDiscount: [
          {
            required: true, message: "是否特殊优惠不能为空", trigger: "blur"
          }
        ],
        discount0: [
          {
            required: true, message: "0#优惠不能为空", trigger: "blur"
          }
        ],
        discount10: [
          {
            required: true, message: "-10#优惠不能为空", trigger: "blur"
          }
        ],
        discount92: [
          {
            required: true, message: "92#优惠不能为空", trigger: "blur"
          }
        ],
        discount95: [
          {
            required: true, message: "95优惠不能为空", trigger: "blur"
          }
        ],
        discount98: [
          {
            required: true, message: "98#优惠不能为空", trigger: "blur"
          }
        ],
        balanceWarningValue: [
          {
            required: true, message: "余额报警值不能为空", trigger: "blur"
          }
        ],
        rechargeActUid: [
          {
            required: true, message: "充值活动uid不能为空", trigger: "blur"
          }
        ],
        cardSecondCount: [
          {
            required: true, message: "副卡数量不能为空", trigger: "blur"
          }
        ],
        remark: [
          {
            required: true, message: "备注信息不能为空", trigger: "blur"
          }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    formatDateTime,
    /** 查询主卡信息列表 */
    getList() {
      this.loading = true;
      listMaster(this.queryParams).then(response => {
        this.masterList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        cardNo: undefined,
        stationId: undefined,
        memberId: undefined,
        cardName: undefined,
        cardType: undefined,
        cardStatus: undefined,
        balance: undefined,
        capitalBalance: undefined,
        giftBalance: undefined,
        invoiceType: undefined,
        usableFuel: undefined,
        usableStation: undefined,
        comparableFuel: undefined,
        points: undefined,
        discountType: undefined,
        buildDate: undefined,
        username: undefined,
        phone: undefined,
        idCardNo: undefined,
        carNumber: undefined,
        companyId: undefined,
        address: undefined,
        password: undefined,
        specialDiscount: undefined,
        discount0: undefined,
        discount10: undefined,
        discount92: undefined,
        discount95: undefined,
        discount98: undefined,
        balanceWarningValue: undefined,
        rechargeActUid: undefined,
        cardSecondCount: undefined,
        creatorId: undefined,
        creatorName: undefined,
        createDate: undefined,
        modifierId: undefined,
        modifierName: undefined,
        modifiedDate: undefined,
        active: undefined,
        remark: undefined,
        version: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSortChange(data) {
      console.log('handleSortChange')
      console.log(data)
      if (data.order) {
        if (data.order.indexOf('asc') > -1) {
          this.queryParams.sortOrder = 'asc'
        } else {
          this.queryParams.sortOrder = 'desc'
        }
        this.queryParams.sortName = data.prop
      }
      console.log(this.queryParams)
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加主卡信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getMaster(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改主卡信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateMaster(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addMaster(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除主卡信息编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delMaster(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/master/export', {
        ...this.queryParams
      }, `master_${nowCnFormatDateTime()}.xlsx`)
    }
  }
}

</script>

<style>
.el-form .el-select {
  width: 100%;
}
</style>
